<template>
  <el-dropdown trigger="click" style="height:100%">
    <span class="el-dropdown-link">
      <el-avatar src="https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg" fit="fill"/>
      <span>{{ userStore.username }}</span>
    </span>
    <template #dropdown>
      <el-dropdown-menu>
        <el-dropdown-item :icon="Plus">修改资料</el-dropdown-item>
        <el-dropdown-item :icon="CircleCheck" @click="logout">退出登录</el-dropdown-item>
      </el-dropdown-menu>
    </template>
  </el-dropdown>
</template>

<script setup lang="ts">
import {
  CircleCheck,
  Plus,
} from '@element-plus/icons-vue'
import useUserStore from "@/store/user";
import {useRouter} from "vue-router";
import useMenuStore from "@/store/menu";
import useTabStore from "@/store/tab";

const userStore = useUserStore()
const menuStore = useMenuStore()
const tabStore = useTabStore()
const router = useRouter()

//退出登录
const logout = ()=> {
  userStore.logout()
  menuStore.flush()
  tabStore.flush()
  router.push('/auth/login')
}
</script>

<style scoped lang="less">
.el-dropdown-link{
  display: flex;
  justify-content: space-between;
  align-items: center;
  span{
    padding-left: 10px;
  }
}
</style>